/**
  ******************************************************************************
  * @文件名           : dri_master.c
  * @作者             : citunhk
  * @功能介绍         : RS485主机驱动
  *	@日期             : 2022.11.1
  ******************************************************************************
  * @注意
  *
  *
  *
  ******************************************************************************
  *更改记录
  *日期 修改人 修改内容
  *
  *
  *
  ******************************************************************************
  */
#include "dri_master.h"
#include "bsp_usart.h"
#include "fml_crc.h"

uint8_t pBus485_Master_TxBuffer[RS485_MASTER_TX_NUM];
uint8_t gBus485_Master_RxBuffer[RS485_MASTER_RX_NUM];
uint8_t gBus485_Master_RxCounter=0x00;   //主机接收计数
uint8_t pBus485_Master_TxCounter=0x00;   //主机发送计数
uint16_t gStateFinishMaster03 = 0;  //03接收成功状态
uint16_t gStateFinishMaster16 = 0;  //16接收成功状态
uint8_t gStateFinishMaster0203 = 0;  //变频器03接收成功状态
uint8_t gStateFinishMaster0206 = 0;  //变频器06接收成功状态

/**
* @函数名	DRI_MakeModbusMasterUpMsgCrc
* @功能	    生成主机发送数组中的CRC
* @入口参数	无
* @返回值	无
*/
void DRI_MakeModbusMasterUpMsgCrc(void)
{
	uint16_t uiCRCResult;

//	Crc16Arg.pCrc16ArgsPuchMsg=pBus485_Master_TxBuffer;
//	Crc16Arg.crc16ArgsPuchMsgLen=pBus485_Master_TxCounter;
	uiCRCResult = Crc16(pBus485_Master_TxBuffer, pBus485_Master_TxCounter);

//	uiCRCResult=Crc16Arg.returnValue;
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++]=uiCRCResult&0x00FF;
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++]=uiCRCResult>>8;
}

/**
* @函数名	DRI_MasterUpStartTx
* @功能	    主机发送数据
* @入口参数	无
* @返回值	无
*/
void DRI_MasterUpStartTx(void)
{
	BSP_RS485_Master(RS485_Master_Tx);
	BSP_Usart_SendU8(USART2,pBus485_Master_TxBuffer,pBus485_Master_TxCounter);
	LL_mDelay(1);
	BSP_RS485_Master(RS485_Master_Rx);
}

/**
* @函数名	DRI_Master_01TX_Cmd03
* @功能	    作为主机发送整合函数
* @入口参数	无
* @返回值	无
*/
void DRI_Master_01TX_Cmd03(void)
{
	pBus485_Master_TxCounter = 0;

	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x01;  //地址
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x03;  //功能码
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址低位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数量高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x2B;  //数量低位

	DRI_MakeModbusMasterUpMsgCrc();
	DRI_MasterUpStartTx();
}

/**
* @函数名	DRI_Master_02TX_Cmd03
* @功能	    作为主机发送给变频器整合函数
* @入口参数	无
* @返回值	无
*/
void DRI_Master_02TX_Cmd03(uint16_t addr,uint16_t num)
{
	pBus485_Master_TxCounter = 0;

	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //地址
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x03;  //功能码
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(addr>>8));  //起始地址高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = (uint8_t)addr;  //起始地址低位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(num>>8));  //个数高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = (uint8_t)num;  //个数低位

	DRI_MakeModbusMasterUpMsgCrc();
	DRI_MasterUpStartTx();
}

/**
* @函数名	DRI_Master_02TX_Cmd06
* @功能	    作为主机发送整合函数
* @入口参数	无
* @返回值	无
*/
void DRI_Master_02TX_Cmd06(uint16_t addr,uint16_t data)
{
	pBus485_Master_TxCounter = 0;

	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //地址
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x06;  //功能码
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(addr>>8));  //起始地址高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = (uint8_t)addr;  //起始地址低位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(data>>8));  //数据高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = (uint8_t)data;  //数据低位

	DRI_MakeModbusMasterUpMsgCrc();
	DRI_MasterUpStartTx();
}

/**
* @函数名	DRI_Master_01TX_Cmd16
* @功能	    作为主机发送整合函数
* @入口参数	无
* @返回值	无
*/
void DRI_Master_01TX_Cmd16(void)
{
	pBus485_Master_TxCounter = 0;

	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x01;  //地址
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x10;  //功能码
	if(gEnableDataEEV1 == 1)
	{
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x32;  //起始地址低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数量高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x01;  //数量低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //字节数

		gUpDownDataEEV1 = gUpDownData2EEV1*10;
//		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //电子膨胀阀1状态
//		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gUpDownEEV1;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(gUpDownDataEEV1>>8));  //电子膨胀阀1圈数
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gUpDownDataEEV1;
		gEnableDataEEV1 = 0;
	}
	else if(gEnableDataEEV2 == 1)
	{
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x33;  //起始地址低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数量高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x01;  //数量低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //字节数

		gUpDownDataEEV2 = gUpDownData2EEV2*10;
//		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //电子膨胀阀2状态
//		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gUpDownEEV2;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(gUpDownDataEEV2>>8));  //电子膨胀阀2圈数
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gUpDownDataEEV2;
		gEnableDataEEV2 = 0;
	}
	else if(gEnableDataEEV3 == 1)
	{
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x34;  //起始地址低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数量高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x01;  //数量低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //字节数

		gUpDownDataEEV3 = gUpDownData2EEV3*10;
//		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //电子膨胀阀3状态
//		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gUpDownEEV3;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(gUpDownDataEEV3>>8));  //电子膨胀阀3圈数
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gUpDownDataEEV3;
		gEnableDataEEV3 = 0;
	}
	else  //运行参数
	{
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x38;  //起始地址低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数量高位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x2D;  //数量低位
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x5A;  //字节数

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数字量输出1
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gSlaver_DigitalOut1;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数字量输出2
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gSlaver_DigitalOut2;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数字量输出3
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gSlaver_DigitalOut3;

		utf.f = gSV_Temp1;  //主温度算法设定值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = gPV_TempPID1;  //主温度实测值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //压缩机启停状态
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gLastState_Comp;

		utf.f = UP.Para.TempPID_P1;  //控温_P1值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_I1;  //控温_I1值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_D1;  //控温_D1值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_P;  //控温_P值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_I;  //控温_I值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_D;  //控温_D值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_P3;  //控温_P3值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_I3;  //控温_I3值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = UP.Para.TempPID_D3;  //控温_D3值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //电子膨胀阀控制方式标志
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = gFlag_Auto;

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //预留
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //预留
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //预留
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //预留
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //预留
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //高温辅助制冷电子膨胀阀使能
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = FP.Para.ES_EEV3;

		utf.f = FP.Para.Tup1;  //高温辅助制冷电子膨胀阀上限温度1
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = FP.Para.Tup2;  //高温辅助制冷电子膨胀阀上限温度2
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = FP.Para.Tdown1;  //高温辅助制冷电子膨胀阀下限温度1
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = FP.Para.Tdown2;  //高温辅助制冷电子膨胀阀下限温度2
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		utf.f = FP.Para.SV_Alarm_Press1;  //从机氟压1报警下限值
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>24));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>16));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(utf.u>>8));
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = utf.u;

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //预留
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;

		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0;  //高温辅助制冷电子膨胀阀使能
		pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = FP.Para.EEV1_Min;
	}

	DRI_MakeModbusMasterUpMsgCrc();
	DRI_MasterUpStartTx();
}

/**
* @函数名	DRI_Master_02TX_Cmd16
* @功能	    作为主机发送整合函数
* @入口参数	无
* @返回值	无
*/
void DRI_Master_02TX_Cmd16(void)
{
	pBus485_Master_TxCounter = 0;

	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //地址
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x10;  //功能码
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //起始地址高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x69;  //起始地址低位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x00;  //数量高位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x02;  //数量低位
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = 0x04;  //字节数

	//操作频率
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(FP.Para.Fre_Pump_MAX>>8));
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = (uint8_t)FP.Para.Fre_Pump_MAX;  //水泵最大操作频率
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = ((uint8_t)(FP.Para.Fre_Pump_MIN>>8));
	pBus485_Master_TxBuffer[pBus485_Master_TxCounter++] = (uint8_t)FP.Para.Fre_Pump_MIN;  //水泵最小操作频率

	DRI_MakeModbusMasterUpMsgCrc();
	DRI_MasterUpStartTx();
}

/**
* @函数名	DRI_ProcessModbusMasterUp03Cmd3
* @功能	    03指令处理
* @入口参数	无
* @返回值	无
*/
void DRI_ProcessModbusMasterUp03Cmd3(void)
{
	gSlaver_DigitalIn1 = gBus485_Master_RxBuffer[4];  //数字量输入1

	gSlaver_DigitalIn2 = gBus485_Master_RxBuffer[6];  //数字量输入2

	gSlaver_DigitalIn3 = gBus485_Master_RxBuffer[8];  //数字量输入3

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[9]<<24)+((uint32_t)gBus485_Master_RxBuffer[10]<<16)+((uint32_t)gBus485_Master_RxBuffer[11]<<8)+((uint32_t)gBus485_Master_RxBuffer[12]);   //温度1
	gSlaver_Temp1 = utf.f;

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[13]<<24)+((uint32_t)gBus485_Master_RxBuffer[14]<<16)+((uint32_t)gBus485_Master_RxBuffer[15]<<8)+((uint32_t)gBus485_Master_RxBuffer[16]);   //温度2
	gSlaver_Temp2 = utf.f;

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[17]<<24)+((uint32_t)gBus485_Master_RxBuffer[18]<<16)+((uint32_t)gBus485_Master_RxBuffer[19]<<8)+((uint32_t)gBus485_Master_RxBuffer[20]);   //温度3
	gSlaver_Temp3 = utf.f;

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[21]<<24)+((uint32_t)gBus485_Master_RxBuffer[22]<<16)+((uint32_t)gBus485_Master_RxBuffer[23]<<8)+((uint32_t)gBus485_Master_RxBuffer[24]);   //压力1
	gSlaver_Press1 = utf.f;

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[25]<<24)+((uint32_t)gBus485_Master_RxBuffer[26]<<16)+((uint32_t)gBus485_Master_RxBuffer[27]<<8)+((uint32_t)gBus485_Master_RxBuffer[28]);   //压力2
	gSlaver_Press2 = utf.f;

	gUpDownData1EEV1 = ((uint16_t)gBus485_Master_RxBuffer[29]<<8)+gBus485_Master_RxBuffer[30];  //电子膨胀阀1开度

	gUpDownData1EEV2 = ((uint16_t)gBus485_Master_RxBuffer[31]<<8)+gBus485_Master_RxBuffer[32];  //电子膨胀阀2开度

	gUpDownData1EEV3 = ((uint16_t)gBus485_Master_RxBuffer[33]<<8)+gBus485_Master_RxBuffer[34];  //电子膨胀阀3开度

	gFlag_EEVInitOver1 = gBus485_Master_RxBuffer[36];  //初始化完成标志

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[37]<<24)+((uint32_t)gBus485_Master_RxBuffer[38]<<16)+((uint32_t)gBus485_Master_RxBuffer[39]<<8)+((uint32_t)gBus485_Master_RxBuffer[40]);  //从机压力1饱和温度
	gSlaver_Press_Temp1 = utf.f;

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[41]<<24)+((uint32_t)gBus485_Master_RxBuffer[42]<<16)+((uint32_t)gBus485_Master_RxBuffer[43]<<8)+((uint32_t)gBus485_Master_RxBuffer[44]);   //从机压力1过热度
	gSlaver_Superhest_Press1 = utf.f;

	gState_CoolHeater = ((uint16_t)gBus485_Master_RxBuffer[73]<<8)+gBus485_Master_RxBuffer[74];  //制冷加热状态图标

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[75]<<24)+((uint32_t)gBus485_Master_RxBuffer[76]<<16)+((uint32_t)gBus485_Master_RxBuffer[77]<<8)+((uint32_t)gBus485_Master_RxBuffer[78]);   //从机压力2饱和温度
	gSlaver_Press_Temp2 = utf.f;

	utf.u = ((uint32_t)gBus485_Master_RxBuffer[79]<<24)+((uint32_t)gBus485_Master_RxBuffer[80]<<16)+((uint32_t)gBus485_Master_RxBuffer[81]<<8)+((uint32_t)gBus485_Master_RxBuffer[82]);   //从机压力1过热度
	gSlaver_Supercold_Press2 = utf.f;

	gSlaver_Version = ((uint16_t)gBus485_Master_RxBuffer[85]<<8)+gBus485_Master_RxBuffer[86];  //D4306软件版本

	gSlaver_Ref = ((uint16_t)gBus485_Master_RxBuffer[87]<<8)+gBus485_Master_RxBuffer[88];  //冷媒种类

	if(FP.Para.Type_Press1 == 0)  //蒸发压力下限值根据氟种自动设置
	{
		if(gSlaver_Ref == 1)//R404a
		{
			FP.Para.SV_Alarm_Press1 = 80.0;
		}
		if(gSlaver_Ref == 2)//R410a
		{
			FP.Para.SV_Alarm_Press1 = 150.0;
		}
	}
//	utf.u = ((uint32_t)gBus485_Master_RxBuffer[53]<<24)+((uint32_t)gBus485_Master_RxBuffer[54]<<16)+((uint32_t)gBus485_Master_RxBuffer[55]<<8)+((uint32_t)gBus485_Master_RxBuffer[56]);   //从机P值
//	gSlaver_P = utf.f;
//
//	utf.u = ((uint32_t)gBus485_Master_RxBuffer[57]<<24)+((uint32_t)gBus485_Master_RxBuffer[58]<<16)+((uint32_t)gBus485_Master_RxBuffer[59]<<8)+((uint32_t)gBus485_Master_RxBuffer[60]);   //从机I值
//	gSlaver_I = utf.f;
//
//	utf.u = ((uint32_t)gBus485_Master_RxBuffer[61]<<24)+((uint32_t)gBus485_Master_RxBuffer[62]<<16)+((uint32_t)gBus485_Master_RxBuffer[63]<<8)+((uint32_t)gBus485_Master_RxBuffer[64]);   //从机D值
//	gSlaver_D = utf.f;
//
//	utf.u = ((uint32_t)gBus485_Master_RxBuffer[65]<<24)+((uint32_t)gBus485_Master_RxBuffer[66]<<16)+((uint32_t)gBus485_Master_RxBuffer[67]<<8)+((uint32_t)gBus485_Master_RxBuffer[68]);   //从机PID和
//	gSlaver_PID = utf.f;
//
//	utf.u = ((uint32_t)gBus485_Master_RxBuffer[69]<<24)+((uint32_t)gBus485_Master_RxBuffer[70]<<16)+((uint32_t)gBus485_Master_RxBuffer[71]<<8)+((uint32_t)gBus485_Master_RxBuffer[72]);   //从机PID平均值
//	gSlaver_ValuePID = utf.f;
}

/**
* @函数名	DRI_ProcessModbusMasterUp02Cmd3
* @功能	    03指令处理
* @入口参数	无
* @返回值	无
*/
void DRI_ProcessModbusMasterUp02Cmd3(void)
{
	uint16_t pFlag_Comp = 0;
	pFlag_Comp = ((uint16_t)gBus485_Master_RxBuffer[3]<<8)+(uint16_t)gBus485_Master_RxBuffer[4];  //模拟量输入1AD值

	if(pFlag_Comp & 0x0001)
		rFlag_Comp = rFlag_Comp | 0x0001;
	if(pFlag_Comp & 0x0002)
		rFlag_Comp = rFlag_Comp | 0x0002;
	if(pFlag_Comp & 0x0004)
		rFlag_Comp = rFlag_Comp | 0x0004;
	if(pFlag_Comp & 0x0008)
		rFlag_Comp = rFlag_Comp | 0x0008;
	if(pFlag_Comp & 0x0010)
		rFlag_Comp = rFlag_Comp | 0x0010;
	if(pFlag_Comp & 0x0020)
		rFlag_Comp = rFlag_Comp | 0x0020;
	if(pFlag_Comp & 0x0040)
		rFlag_Comp = rFlag_Comp | 0x0040;
	if(pFlag_Comp & 0x0080)
		rFlag_Comp = rFlag_Comp | 0x0080;
	if(pFlag_Comp & 0x0100)
		rFlag_Comp = rFlag_Comp | 0x0100;
	if(pFlag_Comp & 0x0200)
		rFlag_Comp = rFlag_Comp | 0x0200;
	if(pFlag_Comp & 0x0400)
		rFlag_Comp = rFlag_Comp | 0x0400;
	if(pFlag_Comp & 0x0800)
		rFlag_Comp = rFlag_Comp | 0x0800;
	if(pFlag_Comp & 0x1000)
		rFlag_Comp = rFlag_Comp | 0x1000;
	if(pFlag_Comp & 0x2000)
		rFlag_Comp = rFlag_Comp | 0x2000;
	if(pFlag_Comp & 0x4000)
		rFlag_Comp = rFlag_Comp | 0x4000;
	if(pFlag_Comp & 0x8000)
		rFlag_Comp = rFlag_Comp | 0x8000;
}

/**
* @函数名	DRI_ProcessModbusMasterUp01Cmd6
* @功能	    06指令处理
* @入口参数	无
* @返回值	无
*/
void DRI_ProcessModbusMasterUp01Cmd6(void)
{

}

/**
* @函数名	DRI_ProcessModbusMasterUp02Cmd6
* @功能	    06指令处理
* @入口参数	无
* @返回值	无
*/
void DRI_ProcessModbusMasterUp02Cmd6(void)
{
	gComp_Data1 = ((uint16_t)gBus485_Master_RxBuffer[4]<<8)+(uint16_t)gBus485_Master_RxBuffer[5];
}

/**
* @函数名	DRI_ProcessModbusMasterUp01Cmd16
* @功能	    16指令处理
* @入口参数	无
* @返回值	无
*/
void DRI_ProcessModbusMasterUp01Cmd16(void)
{

}

/**
* @函数名	Task_Master_RX_Integration
* @功能	    RS485接收数据处理
* @入口参数	无
* @返回值	无
*/
void DRI_Master_RX_Integration(void)
{
	static uint16_t uiCRCResult;
	uint8_t pModbusUpFrameMasterStatus=1;
	if(gBus485_Master_RxCounter<3) //如果数据字节少于3
	{
		pModbusUpFrameMasterStatus=1;
	}
	else
	{
		uint16_t crcdata;
//		Crc16Arg.pCrc16ArgsPuchMsg=gBus485_Master_RxBuffer;  //获取等待CRC数组地址
//		Crc16Arg.crc16ArgsPuchMsgLen=gBus485_Master_RxCounter-2;  //获取等待CRC数组长度  不包含原CRC
		uiCRCResult = Crc16(gBus485_Master_RxBuffer, gBus485_Master_RxCounter-2);
//		uiCRCResult=Crc16Arg.returnValue;  //得到CRC数值
		crcdata = (gBus485_Master_RxBuffer[gBus485_Master_RxCounter-1]<<8)|(gBus485_Master_RxBuffer[gBus485_Master_RxCounter-2]);
		gBus485_Master_RxCounter = 0;
		if((crcdata - uiCRCResult) == 0)//CRC校验通过
		{
			pModbusUpFrameMasterStatus=0;  //接收成功
		}
		else
		{
			pModbusUpFrameMasterStatus=1;//接收失败
		}
	}
	if(pModbusUpFrameMasterStatus==0)
	{
		if(gBus485_Master_RxBuffer[0]==0x01)
		{
			switch(gBus485_Master_RxBuffer[1])  //判断指令
			{
				case 3://跳转至03H指令
					gStateFinishMaster03 = 0;
					DRI_ProcessModbusMasterUp03Cmd3();
					break;
				case 6://写单个寄存器
					DRI_ProcessModbusMasterUp01Cmd6();
					break;
				case 16://写多个寄存器
					gStateFinishMaster16 = 0;
					DRI_ProcessModbusMasterUp01Cmd16();
					break;
				default://ÀýÍâ´¦Àí
					//ExceptionResponse(0x01);
				break;
			}
		}
		else if(gBus485_Master_RxBuffer[0]==0x02)
		{
			switch(gBus485_Master_RxBuffer[1])  //判断指令
			{
				case 3://跳转至04H指令
					gStateFinishMaster0203 = 0;
					DRI_ProcessModbusMasterUp02Cmd3();
					break;
				case 6://写单个寄存器
					gStateFinishMaster0206 = 0;
					DRI_ProcessModbusMasterUp02Cmd6();
					break;
				case 16://写多个寄存器
					DRI_ProcessModbusMasterUp01Cmd16();
					break;
				default://ÀýÍâ´¦Àí
					//ExceptionResponse(0x01);
				break;
			}
		}
	}
}







